package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.RecruitPlan;
import cn.wolfcode.crm.mapper.RecruitPlanMapper;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.query.RequireQueryObject;
import cn.wolfcode.crm.service.IRecruitPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RecruitPlanServiceImpl implements IRecruitPlanService {

    @Autowired
    private RecruitPlanMapper recruitPlanMapper;

    public void insert(RecruitPlan entity) {
        entity.setInputTime(new Date());
        entity.setInputUser(new Employee());//设置登录用户为申请人
        recruitPlanMapper.insert(entity);
    }

    public void delete(Long id) {
        recruitPlanMapper.deleteByPrimaryKey(id);
    }

    public void update(RecruitPlan entity) {
        recruitPlanMapper.updateByPrimaryKey(entity);
    }

    public RecruitPlan get(Long id) {
        return  recruitPlanMapper.selectByPrimaryKey(id);
    }

    public List<RecruitPlan> list() {
        return  recruitPlanMapper.selectAll();
    }

    public PageResult query(RequireQueryObject qo) {
        int total =  recruitPlanMapper.queryForCount(qo);
        List<RecruitPlan> rows =  recruitPlanMapper.queryForList(qo);
        return new PageResult(total,rows);
    }

    public void audit(Long id) {
        RecruitPlan recruitPlan = recruitPlanMapper.selectByPrimaryKey(id);
        recruitPlan.setAuditor(new Employee());//设置当前登录用户为审核人
        recruitPlan.setAuditTime(new Date());
        recruitPlan.setState(RecruitPlan.STATE_OPEN);
        recruitPlanMapper.updateByPrimaryKey(recruitPlan);

    }
}
